package com.zenq.ssm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.zenq.ssm.entity.Product;
import com.zenq.ssm.mapper.ProductMapper;

@Service
public class ProductService {

	@Autowired
	private ProductMapper productMapper;
	/**
	 * 添加商品
	 * @param product
	 * @return
	 */
	public int add(Product product) {
		return productMapper.insert(product);
	}
	/**
	 * 修改商品信息
	 * @param product
	 * @return
	 */
	public int update(Product product) {
		return productMapper.updateByPrimaryKey(product);
	}
	/**
	 * 根据主键查询单个商品信息
	 * @param productId
	 * @return
	 */
	public Product getById(int productId) {
		return productMapper.selectByPrimaryKey(productId);
	}
	/**
	 * 修改商品状态：上架/下架
	 * @param product
	 * @return
	 */
	public int updateStatus(Product product) {
		return productMapper.updateByPrimaryKeySelective(product);
	}
	/**
	 * 分页查询商品列表
	 * @param p
	 * @param page
	 * @param rows
	 * @return
	 */
	public List<Product> getProductPage(Product p, int page, int rows) {
		PageHelper.startPage(page, rows);
		return productMapper.selectByCondition(p);
	}
}
